<template>
    <div class="do-record">
        <div class="do-record-card">
            <div class="do-record-head">
                <Row :gutter="5">
                    <Col span="4">
                        <DatePicker  clearable v-model="searchData.timeStartEnd" style="width: 100%" type="daterange" placeholder="时间筛选"></DatePicker>
                    </Col>
                    <Col span="4">
                        <Input clearable v-model="searchData.username" placeholder="用户名" type="text"></Input>
                    </Col>
                    <Col span="4">
                        <Input clearable v-model="searchData.content" placeholder="操作内容" type="text"></Input>
                    </Col>
                    <Col span="4">
                        <Select clearable v-model="searchData.sort" placeholder="时间排序">
                            <Option :value="1">升序</Option>
                            <Option :value="2">降序</Option>
                        </Select>
                    </Col>
                    <Col span="8">
                        <Button :loading="search_loading" @click="searchGetList" class="subSearch" type="primary"><Icon type="ios-pulse-strong"></Icon> 筛 选</Button>
                    </Col>
                </Row>
            </div>
            <i-table height="685" stripe :columns="columns" :data="data"></i-table>
            <div style="padding: 15px;">
                <Page @on-page-size-change="changeTiao" @on-change="changePage" :current="index" :total="total" show-elevator show-sizer :placement="'top'" :page-size="page_con" :page-size-opts="[10, 15, 20, 30, 40, 50]"></Page>
            </div>
        </div>
        <!--查看地址-->
        <Modal v-model="modal2" width="360">
            <p slot="header" style="text-align:center">
                <a>
                    <Icon type="information-circled"></Icon>
                    <span>地址查看</span>
                </a>
            </p>
            <div style="text-align:center">
                <p>{{address}}</p>
            </div>
            <div slot="footer">
                <Button type="primary" size="large" long  @click="modal2 = false">确定</Button>
            </div>
        </Modal>
    </div>
</template>
<script>
    export default {
        name:"do-record",
        data(){
            return{
                columns:[
                    {
                        title: '序号',
                        type: 'index',
                        width: 60,
                        align:"center",
                    },
                    {
                        title: '用户名',
                        key: 'username',
                        align:"center",
                    },
                    {
                        title: '操作内容',
                        key: 'content',
                        align:"center",
                    },
                    {
                        title: 'IP',
                        key: 'ip',
                        align:"center",
                    },
                    {
                        title: '操作时间',
                        key: 'dotime',
                        align:"center",
                        render:(h,params)=>{
                            return `${this.timeFormat(params.row.dotime)}`
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        render: (h, params) => {
                            return h('ButtonGroup', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                    },
                                    on: {
                                        click: () => {
                                            this.ip = params.row.ip
                                            this.looKAddress()
                                        }
                                    }
                                },"查看地址"),
                            ]);
                        }
                    },
                ],
                data:[],
                total:0,
                index:1,
                page_con:15,
                searchData:{
                    timeStartEnd:[],//两个时间内的赛选
                    username:"",//用户名
                    content:"",//操作内容
                    sort:"",//排序
                },
                search_loading:false,
                modal2:false,
                ip:"",
                address:""
            }
        },
        activated(){
            this.getData()
        },
        methods:{
            getData(){
                this.getJsonData("Log/getLog",{
                    num:this.page_con,
                    page:this.index,
                    begin:this.searchData.timeStartEnd[0]?this.searchData.timeStartEnd[0]/1000:"",
                    last:this.searchData.timeStartEnd[1]?this.searchData.timeStartEnd[1]/1000:"",
                    username:this.searchData.username,
                    content:this.searchData.content,
                    sort:this.searchData.sort,
                },true)
                    .then((res)=>{
                        this.data=res.data
                        this.total=parseInt(res.count)
                        this.search_loading=false
                    })
                    .catch((res)=>{
                        this.search_loading=false
                    })
            },
            changePage(n){
                this.index=n
                this.getData()
            },
            changeTiao(num){
                this.page_con=num
                this.index=1
                this.getData()
            },
            searchGetList(){
                this.search_loading=true
                this.index=1
                this.getData()
            },
            looKAddress(){
                this.getJsonData("Log/getIpAddress",{
                    ip:this.ip
                },true)
                    .then((res)=>{
                        let obj = JSON.parse(res.data).data
                        this.address=`${obj.country}-${obj.region}-${obj.city}-${obj.isp}`
                        this.modal2 = true
                    })
            }
        },
    }
</script>
<style lang="less">
    @import "do-record";
</style>